const install = (Vue, vm) => {
	const isLogin = () => {
		const token = vm.vuex_token;
		if (!token) {
			const { options, route } = getCurrentPages().pop();
			const keys = Object.keys(options);
			let params = '';
			if (keys.length) {
				params = keys.reduce((cur, pre) => `${cur+pre}=${options[pre]}&`, '?').slice(0, -1);
			}
			uni.setStorageSync('back_url', route + params);
			vm.$u.toast('请登录')
			setTimeout(() => {
				vm.$u.route({
					type: 'redirect',
					url: 'pages/auth/login'
				})
			}, 1500);
			return false;
		}
		return true;
	}
	const updateUser = async () => {
		const userInfo = await vm.$u.api.userInfo();
		vm.$u.vuex('vuex_user', userInfo);
	};
	vm.$u.utils = {
		isLogin,
		updateUser
	}
}

export default {
	install
}